package cn.iocoder.yudao.module.fengdong.smartelderly.controller.app.reserved;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import cn.iocoder.yudao.module.fengdong.smartelderly.controller.admin.reserved.vo.*;
import cn.iocoder.yudao.module.fengdong.smartelderly.convert.reserved.ReservedConvert;
import cn.iocoder.yudao.module.fengdong.smartelderly.dal.dataobject.reserved.ReservedDO;
import cn.iocoder.yudao.module.fengdong.smartelderly.service.reserved.ReservedService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.util.Collection;
import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT;

@Tag(name = "用户 APP - 预约管理")
@RestController
@RequestMapping("/fengdong.smartelderly/reserved")
@Validated
public class AppReservedController {

    @Resource
    private ReservedService reservedService;

    @PostMapping("/create")
    @Operation(summary = "创建预约管理")
    public CommonResult<Long> createReserved(@Valid @RequestBody ReservedCreateReqVO createReqVO) throws IOException {
        return success(reservedService.createReserved(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新预约管理")
    public CommonResult<Boolean> updateReserved(@Valid @RequestBody ReservedUpdateReqVO updateReqVO) {
        reservedService.updateReserved(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除预约管理")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteReserved(@RequestParam("id") Long id) {
        reservedService.deleteReserved(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得预约管理")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<ReservedRespVO> getReserved(@RequestParam("id") Long id) {
        ReservedDO reserved = reservedService.getReserved(id);
        return success(ReservedConvert.INSTANCE.convert(reserved));
    }

    @GetMapping("/list")
    @Operation(summary = "获得预约管理列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<ReservedRespVO>> getReservedList(@RequestParam("ids") Collection<Long> ids) {
        List<ReservedDO> list = reservedService.getReservedList(ids);
        return success(ReservedConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得预约管理分页")
    public CommonResult<PageResult<ReservedRespVO>> getReservedPage(@Valid ReservedPageReqVO pageVO) {
        PageResult<ReservedDO> pageResult = reservedService.getReservedPage(pageVO);
        return success(ReservedConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/Apppage")
    @Operation(summary = "获得预约管理分页---关联查询")
    public CommonResult<IPage<ReservedAppRespVO>> getReservedAppPage(@Valid ReservedAppPageReqVO pageVO) {
        IPage<ReservedAppRespVO> pageResult = reservedService.getAPPReservedPage(pageVO);
        return success(pageResult);
    }
}
